<?php

use Core\AdminController;
use Models\UserLevel;

class UserLevelController extends AdminController
{
    public function index()
    {
        $model = new UserLevel();

        $userLevels = $model->order_by('level asc')->get();

        $this->load->view('admin/userLevel/index', [
            'userLevels' => $userLevels
        ]);
    }

    public function add()
    {
        $model = new UserLevel();
        $model->load($this->input->post());
        $model->add();

        return $this->response($model->to_array());
    }

    public function edit($id)
    {
        $model = new UserLevel();

        $model->findOrFail($id);

        $model->load($this->input->post());
        $model->update();

        return $this->response($model->to_array());
    }

    public function detail($id)
    {
        $model = new UserLevel();

        $model->findOrFail($id);

        return $this->response($model->to_array());
    }

    public function delete($id)
    {
        $model = new UserLevel();

        $model->findOrFail($id);
        $model->delete();

        return $this->response();
    }
}
